<?php
namespace app\index\controller;

class Search extends Base{
	public function index(){
		$keywords = input('param.q');
		if(empty($keywords)){
			header('Location: '.WAP_DOMAIN);
			exit;
		}
		$list = db('picture')->where("`title` like '%$keywords%'")->order('id desc')->paginate(10,false,['query' => request()->param()]);
		$page = $list->render();
		$seo = $this->site();
		$seo['site_title'] = isset($keywords) ? $keywords.' - '.$seo['site_title'] : '全站搜索_'.$seo['site_title'];
        $this->assign('list', $list);
        $this->assign('q', $keywords);
        $this->assign('page', $page);
        $this->assign('seo', $seo);
		return $this->fetch();
	}
	public function gethotkey(){
		$keywords = db('keyword')->limit(20)->order('videonum desc')->select();
		foreach ($keywords as $k => $v) {
			$keywords[$k]['urlencode'] = urlencode($v['keyword']);
		}
		echo json_encode($keywords, JSON_FORCE_OBJECT);
	}
}